/*
	This file is part of SRServerLibrary.
	Foobar is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	SRServerLibrary is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with SRServerLibrary.  If not, see <http://www.gnu.org/licenses/>.
*/

//!Class SRPlugin.cpp
/*!This class will serve as an interface for the actual plugins; an instance of the class will be created for each loaded plugin;

*/


#include "SRPlugin.h"
#include <iostream>
#include <dlfcn.h>

/*
Class acts as an interface between the SRPluginLoader class
and the SRCPlugn interface;
No need for explicit constructor */



  //! SRPlugin parameterless constructor.
    /*!
     An empty constructor for testing purposes at the moment;
    */

SRPlugin::SRPlugin()
{

};


  //! SRPlugin constructor with parameters.
    /*!
	This constructor takes three function pointers to pass on commands to the plugins
	\param int (*initiate_pointer)()
	\param int (*destroy_pointer)()
	\param  string (*doCommand_pointer)(int command)
    */
SRPlugin::SRPlugin(int (*initiate_pointer)(), int (*destroy_pointer)(), char* (*doCommand_pointer)(char* command))
{
	SRPlugin::initiateP = initiate_pointer;
	SRPlugin::destroyP = destroy_pointer;
	SRPlugin::doCommandP = doCommand_pointer;
};


  //! A method to initiate the plugin
    /*!
	SRPlugin::initiate takes a void pointer to the plugin and calls the initiate method of the plugin;
	\param void *p
	\return int
    */
int SRPlugin::initiate()
{
	initiate();
};

  //! A method to destroy the plugin
    /*!
	SRPlugin::destroy takes a void pointer to the plugin and calls the destroy method of the plugin;
	\return int
    */

int SRPlugin::destroy()
{
	destroyP();
};


  //! A method to call a certain action in the plugin
    /*!
	SRPlugin::doCommand takes a string command and passes it on to the plugin for execution;
	\param int command
	\return string
    */

char* SRPlugin::doCommand(char* command)
{
	fprintf(stderr, "in SRPlugin: %s\n", command);
	doCommandP(command);
};


